﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace FGK
{
    class Obrazek
    {
        private uint[,] obraz;
        private Bitmap bit;
        private int szerokosc;
        private int wysokosc;
        
        public uint[,] Obraz
        {
            get { return obraz; }
            set { obraz = value; }
        }

        public int Szerokosc
        {
            get { return szerokosc; }
            set { szerokosc = value; }
        }

        public int Wysokosc
        {
            get { return wysokosc; }
            set { wysokosc = value; }
        }

        public Obrazek(int w, int h)
        {
            this.obraz = new uint[w, h];
            this.wysokosc = h;
            this.szerokosc = w;
        }

        public void setPixel(int i, int j, uint kolor)
        {
            this.obraz[i, j] = kolor;
        }

        public uint getPixel(int i, int j)
        {
            return this.obraz[i, j];
        }

        public void rasterize()
        {
            Console.WriteLine("\n* rasteryzacja");
            int r,g,b;
            bit = new Bitmap(Szerokosc, Wysokosc,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for (int i = 0; i < Szerokosc; i++)
            {
                for (int j = 0; j < Wysokosc; j++)
                {
                    r = (int)((obraz[i,j] >> 16) & 0xff);
                    g = (int)((obraz[i, j] >> 8) & 0xff);
                    b = (int)((obraz[i,j] & 0xff));
                    bit.SetPixel(i, j, Color.FromArgb(r,g,b) );
                }
            }
            try
            {
                Console.WriteLine("* zapis do pliku");
                bit.Save("newimage.jpg");
            }
            finally
            {
                bit.Dispose();
                Console.WriteLine("* zapisano");
            }
        }



    }
}
